import json

import pandas as pd

mock_json = "[{ name: 'Average UV', color: '#FF8533', data: [4, 5, 5, 6, 6, 6, 6, 6, 6, 6, 5, 4]}]"


class Graph:
    def __init__(self) -> None:
        super().__init__()

    def title(self):
        return "Monthly Average UV"

    def json_parse(self, series: str):
        series = series.replace("'", '"')
        series = series.replace("tooltip", '"tooltip"')
        series = series.replace("valueSuffix", '"valueSuffix"')
        series = series.replace("name", '"name"')
        series = series.replace("color", '"color"')
        series = series.replace("type", '"type"')
        series = series.replace("data", '"data"')
        series = series.replace("yAxis", '"yAxis"')
        return json.loads(series)

    def parse_temp(self, data):
        data1 = data[0]['data']
        frame = pd.DataFrame({"Average UV": data1})
        frame.index = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October',
                       'November', 'December']
        return frame

    def parse(self, serise: str):
        parse = self.json_parse(serise)
        temp = self.parse_temp(parse)
        return temp


if __name__ == '__main__':
    graph = Graph()
    parse = graph.parse(mock_json)

    print(parse)
